//
//  HYDeviceControlApi.m
//  TJHYHardwareProduct
//
//  Created by Kendama on 2018/2/28.
//  Copyright © 2018年 Kendama. All rights reserved.
//

#import "HYDeviceControlApi.h"

@implementation HYDeviceControlApi{
    NSDictionary *_dic;
}

-(id)initWithDic:(NSDictionary *)dic{
    if (self = [super init]) {
        _dic = dic;
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/device/device_control";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (id)requestArgument {
    NSMutableDictionary *dic = [NSMutableDictionary getPubdic];
    
    [dic setValuesForKeysWithDictionary:_dic];
    NSString *sign=[NSString getSign:dic];
    [dic setObject:sign forKey:@"sign"];
    return dic;
}


-(void)dealloc
{
    NSLog(@"%@ dealloc",[self class]);
}

+ (void)controlDevice:(NSString *)device_id status:(int)status success:(void(^)(NSDictionary *dic))successBack fail:(void(^)(NSDictionary *dic))failBack
{
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc]init];
    [requestDic setValue:device_id forKey:@"device_id"];
    [requestDic setValue:@(status).stringValue forKey:@"status"];

    
    HYDeviceControlApi *api = [[HYDeviceControlApi alloc]initWithDic:requestDic];
    [api dtStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        if (successBack) {
            successBack(request.responseObject);
        }
    } failure:^(YTKBaseRequest * _Nonnull request) {
        if (failBack) {
            failBack(request.responseObject);
        }
    }];
}

@end
